const App = getApp();
Page({
  data: {
    video_src: 'https://lion.dlaliyun.cn/uploads/music/guoge.mp4',
    isLogin: false,
    cate:1,   
    teamId:0, // 服务队ID（判断是否入会)
    isShow:false,
    disabled:false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this;
    that.setData({
      isLogin: App.checkIsLogin(),
    });
    if (that.data.isLogin) {
      //获取服务队
      that.setData({
        teamId: App.checkTeam()
      });
    }
  },
  onReady: function (res) {
    this.videoContext = wx.createVideoContext('myVideo')
    this.setData({
      isShow: true,
    }); 
  },
  bindPlay: function() {
    this.videoContext.play()
  },
  bindPause: function() {
    this.videoContext.pause()
  },
  videoErrorCallback: function(e) {
    console.log('视频错误信息:')
    console.log(e.detail.errMsg)
  },

  // tab切换
  onChangeNews(e){
    let that = this;
    that.setData({
      cate: e.currentTarget.dataset.id,
      isShow: false,
    }); 
    if(that.data.cate == 1){
       that.setData({
        video_src: 'https://lion.dlaliyun.cn/uploads/music/guoge.mp4',
      }); 
    }else{ 
      that.setData({
        video_src: 'https://lion.dlaliyun.cn/uploads/music/shige.mp4',
      }); 
    }
    setTimeout(function(){
      that.setData({
        isShow: true,
      }); 
    },3000 );
  },
  //下载文件
  downloadFile(e){
    wx.showLoading({title: '文件下载中...'});
    this.setData({disabled: true}); 
    let url = e.currentTarget.dataset.id;
    let appU = url.split('/');
    let fileName = appU[appU.length-1]
    wx.downloadFile({
      url: url,
      filePath: wx.env.USER_DATA_PATH + "/"+fileName,
      success: (result) => {
        console.log("success",result)
        wx.hideLoading()
        this.setData({disabled: false}); 
      },
      fail: (res) => {
        console.log("fail",res)
      },
      complete: (res) => {
        console.log("complete",res)
      },
    })
  },


})